import React from 'react';

const host = '/webim';
// const host = 'http://172.16.6.235:30088/webim';
// const host = 'http://localhost:8080';
export default function IM({ groupId = '', readOnly = true, ...rest }) {
    const ref = React.useRef();

    React.useEffect(() => {
        if (ref.current) {
            ref.current.contentWindow.location.href = ref.current.src;
        }
    }, [groupId]);

    if (!groupId) return null;

    return (
        <div style={{ width: '100%', height: 600 }} {...rest}>
            <iframe
                ref={ref}
                title="webim"
                frameBorder={0}
                src={`${host}/#/?groupId=${groupId}&readOnly=${Number(readOnly)}`}
                style={{ width: '100%', height: '100%' }}
            />
        </div>
    );
}
